#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2022/1/18 15:10
    Desc  :     用例相关表
--------------------------------------
"""
from apps import AbstractBaseModel
from django.db import models

from common.enums.base_enums import ParamTypeEnum
from common.enums.case_enums import CaseTypeEnum, CaseStatusEnum, CaseImportanceEnum, CasePlanStatusEnum, \
    CaseStepsTypeEnum, CaseImportTypeEnum


class CaseBase(AbstractBaseModel):
    """用例基础信息"""

    caseTitle = models.CharField(max_length = 255, help_text = '用例标题')
    caseDesc = models.CharField(
        max_length = 1000, help_text = '用例描述', null = True, blank = True)
    caseStatus = models.IntegerField(
        default = CaseStatusEnum.DRAFT.key, help_text = '用例状态')
    caseSteps = models.TextField(help_text = '用例步骤json文本', null = True, blank = True)
    caseStepsType = models.IntegerField(
        help_text = '用例步骤类型', default = CaseStepsTypeEnum.STEP.key)
    casePreCondition = models.TextField(
        help_text = '前置条件', null = True, blank = True)
    caseModuleId = models.IntegerField(help_text = '用例所属模块')
    caseImportance = models.IntegerField(
        default = CaseImportanceEnum.P0.key, help_text = '重要程度')
    caseVindicatorId = models.IntegerField(
        help_text = '责任人id', null = True, blank = True)
    caseVindicatorName = models.CharField(
        max_length = 255, help_text = '责任人名称', null = True, blank = True)
    caseRunnerId = models.CharField(
        max_length = 255, help_text = '执行人id', null = True, blank = True)
    caseRunnerName = models.CharField(
        max_length = 255, help_text = '执行人姓名', null = True, blank = True)
    caseRunTime = models.BigIntegerField(
        null = True, blank = True, help_text = '执行时间')
    project = models.IntegerField(help_text = '项目id')

    class Meta:
        verbose_name = '测试用例主表'
        verbose_name_plural = verbose_name
        db_table = 'tCaseBase'


class CaseBaseImportHistory(AbstractBaseModel):
    """用例基础信息"""

    caseTitle = models.CharField(max_length = 255, help_text = '用例标题')
    caseDesc = models.CharField(
        max_length = 1000, help_text = '用例描述', null = True, blank = True)
    caseStatus = models.IntegerField(
        default = CaseStatusEnum.DRAFT.key, help_text = '用例状态')
    caseSteps = models.TextField(help_text = '用例步骤json文本', null = True, blank = True)
    caseStepsType = models.IntegerField(
        help_text = '用例步骤类型', default = CaseStepsTypeEnum.STEP.key)
    casePreCondition = models.TextField(
        help_text = '前置条件', null = True, blank = True)
    caseModuleId = models.IntegerField(help_text = '用例所属模块')
    caseImportance = models.IntegerField(
        default = CaseImportanceEnum.P0.key, help_text = '重要程度')
    caseVindicatorId = models.IntegerField(
        help_text = '责任人id', null = True, blank = True)
    caseVindicatorName = models.CharField(
        max_length = 255, help_text = '责任人名称', null = True, blank = True)
    caseRunnerId = models.CharField(
        max_length = 255, help_text = '执行人id', null = True, blank = True)
    caseRunnerName = models.CharField(
        max_length = 255, help_text = '执行人姓名', null = True, blank = True)
    caseRunTime = models.BigIntegerField(
        null = True, blank = True, help_text = '执行时间')
    project = models.IntegerField(help_text = '项目id', null = True, blank = True)

    class Meta:
        verbose_name = '测试用例导入历史表'
        verbose_name_plural = verbose_name
        db_table = 'tCaseBaseHistory'


class CaseDynamic(AbstractBaseModel):
    """用例动态记录表"""
    caseId = models.IntegerField(help_text = 'tCaseBase的Id')
    operateContent = models.CharField(max_length = 1000, help_text = '操作内容')
    caseStatus = models.IntegerField(help_text = '用例状态')

    class Meta:
        verbose_name = '用例动态记录表'
        verbose_name_plural = verbose_name
        db_table = 'tCaseDynamic'


class CaseApiDetail(AbstractBaseModel):
    """接口测试用例详情"""
    caseId = models.IntegerField(help_text = 'tCaseBase的id')
    casePath = models.CharField(max_length = 255, help_text = '用例请求地址')
    caseMethod = models.IntegerField(help_text = '用例请求方法')
    caseHeader = models.TextField(help_text = '请求头', null = True, blank = True)
    caseBody = models.TextField(help_text = "请求参数", null = True, blank = True)
    caseParamType = models.IntegerField(
        default = ParamTypeEnum.QUERY.key, help_text = '参数类型')
    caseEnv = models.IntegerField(null = True, blank = True, help_text = '请求环境')
    project = models.IntegerField(help_text = '项目id', null = True, blank = True)

    class Meta:
        verbose_name = '接口测试用例详情'
        verbose_name_plural = verbose_name
        db_table = 'tCaseApiDetail'


class CaseTestPlan(AbstractBaseModel):
    """测试计划表"""

    name = models.CharField(max_length = 255, help_text = '测试计划名称')
    desc = models.CharField(
        max_length = 1000, help_text = '测试计划描述', null = True, blank = True)
    status = models.IntegerField(
        default = CasePlanStatusEnum.NOT_START.value, help_text = '测试计划状态')
    startTime = models.DateTimeField(help_text = '开始时间')
    endTime = models.DateTimeField(help_text = '结束时间')
    runTime = models.DateTimeField(help_text = '执行时间', null = True, blank = True)
    finishTime = models.DateTimeField(help_text = '完成时间', null = True, blank = True)
    runnerId = models.IntegerField(help_text = '执行人Id')
    runnerName = models.CharField(max_length = 255, help_text = '执行人姓名')
    project = models.IntegerField(help_text = '项目id', null = True, blank = True)


class CaseTestPlanByCase(AbstractBaseModel):
    """测试计划关联用例表"""

    caseTestPlanId = models.IntegerField(help_text = '测试计划id')
    caseId = models.IntegerField(help_text = '用例id')

    class Meta:
        verbose_name = '测试计划关联用例表'
        verbose_name_plural = verbose_name
        db_table = 'tCaseTestPlanByCase'


class CaseReviewPlan(AbstractBaseModel):
    """用例评审计划"""

    name = models.CharField(max_length = 255, help_text = '用例评审计划名称')
    desc = models.CharField(
        max_length = 1000, help_text = '用例评审计划描述', null = True, blank = True)
    status = models.IntegerField(
        default = CasePlanStatusEnum.NOT_START.key, help_text = '用例评审计划状态')
    startTime = models.DateTimeField(help_text = '开始时间')
    endTime = models.DateTimeField(help_text = '结束时间')
    runTime = models.DateTimeField(help_text = '执行时间', null = True, blank = True)
    finishTime = models.DateTimeField(help_text = '完成时间', null = True, blank = True)
    runnerId = models.IntegerField(help_text = '执行人Id')
    runnerName = models.CharField(max_length = 255, help_text = '执行人姓名')
    project = models.IntegerField(help_text = '项目id', null = True, blank = True)


class CaseReviewPlanByCase(AbstractBaseModel):
    """用例关联评审计划表"""

    caseReviewPlanId = models.IntegerField(help_text = '用例评审计划id')
    caseId = models.IntegerField(help_text = '用例id')

    class Meta:
        verbose_name = '用例关联评审计划表'
        verbose_name_plural = verbose_name
        db_table = 'tCaseReviewPlanByCase'


class CaseImportRecord(AbstractBaseModel):
    """用例导入记录表"""
    filePath = models.CharField(max_length = 1000, help_text = '导入文件url')
    fileName = models.CharField(max_length = 255, help_text = '导入文件名称')
    total = models.IntegerField(null = True, blank = True, help_text = '总记录数')
    failureCount = models.IntegerField(null = True, blank = True, help_text = '失败数量')
    successCount = models.IntegerField(null = True, blank = True, help_text = '成功数量')
    isCheck = models.BooleanField(default = False, help_text = '是否校验通过')
    content = models.TextField(null = True, blank = True, help_text = '导入文件原始的内容')
    type = models.IntegerField(default = CaseImportTypeEnum.EXCEL.key, help_text = '用例导入类型')

    class Meta:
        verbose_name = '用例导入记录表'
        verbose_name_plural = verbose_name
        db_table = 'tCaseImportRecord'
        ordering = ['-createTime']
